package com.tedu.parkinglot.parkCard.controller;

import com.tedu.parkinglot.base.response.JsonResult;
import com.tedu.parkinglot.parkCard.pojo.dto.UserParkCardSaveParam;
import com.tedu.parkinglot.parkCard.pojo.entity.UserParkCard;
import com.tedu.parkinglot.parkCard.service.UserParkCardService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RestController
@RequestMapping("/v1/userParkCard")
public class UserParkCardController {
    @Autowired
    private UserParkCardService userParkCardService;

    @GetMapping("/list")
    public JsonResult  list(
            @RequestParam(required = false) Long userId,
            @RequestParam(required = false) String status) {
        // 根据条件筛选用户车位卡
        List<UserParkCard> userParkCards = userParkCardService.findAll(); // 在这里添加过滤逻辑
        log.info("查询车位卡列表：{}", userParkCards);
        return JsonResult.ok(userParkCards);
    }

    @PostMapping("/save")
    public JsonResult save(@RequestBody UserParkCardSaveParam userParkCardSaveParam) {
        userParkCardService.save(userParkCardSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("/update")
    public JsonResult  update(@RequestBody UserParkCardSaveParam userParkCardSaveParam) {
        log.info("更新车位卡信息：{}", userParkCardSaveParam);
        userParkCardService.save(userParkCardSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("/delete/{id}")
    public JsonResult delete(@PathVariable Long id) {
        userParkCardService.delete(id);
        return JsonResult.ok();
    }
}